package com.zone.service.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zone.common.log.annotation.Log;
import com.zone.common.log.enums.BusinessType;
import com.zone.common.security.annotation.RequiresPermissions;
import com.zone.service.domain.SuppliesForm;
import com.zone.service.service.ISuppliesFormService;
import com.zone.common.core.web.controller.BaseController;
import com.zone.common.core.web.domain.AjaxResult;
import com.zone.common.core.utils.poi.ExcelUtil;
import com.zone.common.core.web.page.TableDataInfo;

/**
 * 物品领用单Controller
 * 
 * @author liuyang
 * @date 2025-11-19
 */
@RestController
@RequestMapping("/suppliesForm")
public class SuppliesFormController extends BaseController
{
    @Autowired
    private ISuppliesFormService suppliesFormService;

    /**
     * 查询物品领用单列表
     */
    @RequiresPermissions("service:suppliesForm:list")
    @GetMapping("/list")
    public TableDataInfo list(SuppliesForm suppliesForm)
    {
        startPage();
        List<SuppliesForm> list = suppliesFormService.selectSuppliesFormList(suppliesForm);
        return getDataTable(list);
    }

    /**
     * 导出物品领用单列表
     */
    @RequiresPermissions("service:suppliesForm:export")
    @Log(title = "物品领用单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuppliesForm suppliesForm)
    {
        List<SuppliesForm> list = suppliesFormService.selectSuppliesFormList(suppliesForm);
        ExcelUtil<SuppliesForm> util = new ExcelUtil<SuppliesForm>(SuppliesForm.class);
        util.exportExcel(response, list, "物品领用单数据");
    }

    /**
     * 获取物品领用单详细信息
     */
    @RequiresPermissions("service:suppliesForm:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(suppliesFormService.selectSuppliesFormById(id));
    }

    /**
     * 新增物品领用单
     */
    @RequiresPermissions("service:suppliesForm:add")
    @Log(title = "物品领用单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuppliesForm suppliesForm)
    {
        return toAjax(suppliesFormService.insertSuppliesForm(suppliesForm));
    }

    /**
     * 修改物品领用单
     */
    @RequiresPermissions("service:suppliesForm:edit")
    @Log(title = "物品领用单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuppliesForm suppliesForm)
    {
        return toAjax(suppliesFormService.updateSuppliesForm(suppliesForm));
    }

    /**
     * 删除物品领用单
     */
    @RequiresPermissions("service:suppliesForm:remove")
    @Log(title = "物品领用单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(suppliesFormService.deleteSuppliesFormByIds(ids));
    }
}
